﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace navigation.Data
{
    public class UserStory : INotifyPropertyChanged
    {
        private string storyName;
        private string state;
        private string storyCardColor;
        private string storyContent;
        private int storyPoints;
        private ObservableCollection<Task> taskList;
        private ObservableCollection<Task> planned;
        private ObservableCollection<Task> inProgress;
        private ObservableCollection<Task> done;
        private string showTaskList = "Collapsed";
        private string storyContentState = "Collapsed";
        
        public string StoryName
        {
            set { storyName = value; }
            get { return storyName; }
        }

        public string State
        {
            set
            {
                state = value;
                SendPropertyChanged("State");
            }
            get { return state; }
        }

        public string StoryCardColor
        {
            set { storyCardColor = value; }
            get { return storyCardColor; }
        }

        public string StoryContent
        {
            set { storyContent = value; }
            get { return storyContent; }
        }

        public int StoryPoints
        {
            set
            {
                storyPoints = value;
                SendPropertyChanged("StoryPoints");
            }
            get
            {
                return storyPoints;
            }
        }

        public object DraggedElement
        {
            get;
            set;
        }

        public ObservableCollection<Task> TaskList
        {
            get
            {
                if (taskList == null)
                {
                    taskList = new ObservableCollection<Task>();
                }

                return taskList;
            }            
        }

        public ObservableCollection<Task> Planned
        {
            get
            {
                if (planned == null)
                {
                    planned = new ObservableCollection<Task>();
                }

                return planned;
            }
        }

        public ObservableCollection<Task> InProgress
        {
            get
            {
                if (inProgress == null)
                {
                    inProgress = new ObservableCollection<Task>();
                }

                return inProgress;
            }
        }

        public ObservableCollection<Task> Done
        {
            get
            {
                if (done == null)
                {
                    done = new ObservableCollection<Task>();
                }

                return done;
            }
        }

        public string StoryContentState
        {
            set
            {
                storyContentState = value;
                SendPropertyChanged("storyContentState");
            }
            get { return storyContentState; }
        }

        public string ShowTaskList
        {
            set
            {
                showTaskList = value;
                SendPropertyChanged("showTaskList");
            }
            get { return showTaskList; }
        }       

               
        private void SendPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                var e = new PropertyChangedEventArgs(propertyName);
                this.PropertyChanged(this, e);
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public UserStory(string storyName, string state, string storyContent)
        {
            this.storyName = storyName;
            //this.state = state;

            switch (state)
            {
                case "planned":
                    this.state = "Red";
                    break;
                case "inprogress":
                    this.state = "Yellow";
                    break;
                case "done":
                    this.state = "Green";
                    break;
            }

            this.storyContent = storyContent;
            this.storyPoints = 10;
        }

        public UserStory(string storyName, string state, string storyContent, int storyPoints, ObservableCollection<Task> tasks)
        {
            this.storyName = storyName;
            //this.state = state;

            switch (state)
            {
                case "planned":
                    this.state = "Red";
                    break;
                case "inprogress":
                    this.state = "Yellow";
                    break;
                case "done":
                    this.state = "Green";
                    break;
            }
            this.storyContent = storyContent;
            this.storyPoints = storyPoints;
            this.taskList = tasks;

            foreach (Task item in taskList)
            {
                if (item.State == "Planned")
                    Planned.Add(item);
                else if (item.State == "InProgress")
                    InProgress.Add(item);
                else if (item.State == "Done")
                    Done.Add(item);
            }
        }

    }
}
